<template>
  <div class="user-wrapper">
    <div class="content-box">
      <lang-select />
      <router-link v-if="$route.name !== 'login'" :to="{ name: 'welcome' }">
        <span class="action">
          <a-icon type="setting" style="font-size: 20px;vertical-align: middle;"></a-icon>
        </span>
      </router-link>
      <a-dropdown v-if="$route.name !== 'login'">
        <span class="action ant-dropdown-link user-dropdown-menu">
          <a-avatar class="avatar" size="small" :src="avatar | imgURLFilter" icon="user" />
          <span>{{ nickname }}</span>
        </span>
        <a-menu slot="overlay" class="user-dropdown-menu-wrapper" @click="handleActions">
          <a-menu-item>
            <router-link :to="{ path: '/account/base' }">
              <a-icon type="user" />
              <span>个人中心</span>
            </router-link>
          </a-menu-item>
          <a-menu-item>
            <router-link :to="{ path: '/account/security' }">
              <a-icon type="setting" />
              <span>修改密码</span>
            </router-link>
          </a-menu-item>
          <a-menu-divider />
          <a-menu-item key="2">
            <a href="javascript:;">
              <a-icon type="logout" />
              <span>退出登录</span>
            </a>
          </a-menu-item>
        </a-menu>
      </a-dropdown>
    </div>
  </div>
</template>

<script>
import LangSelect from '@/components/tools/LangSelect'
import { mapActions, mapGetters } from 'vuex'
export default {
  name: 'UserMenu',
  components: {
    LangSelect
  },
  computed: {
    ...mapGetters(['nickname', 'avatar', 'roles'])
  },
  methods: {
    ...mapActions(['Logout']),
    handleActions ({ key }) {
      if (key === '2') {
        this.handleLogout()
      }
    },
    handleLogout () {
      this.$confirm({
        title: '提示',
        content: '真的要注销登录吗 ?',
        onOk: () => {
          return this.Logout().then(() => {
            window.location.reload()
          })
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.avatar {
  color: inherit !important;
}
</style>
